capture	log close
log using MAR02-SampDiag,  replace text

//  program:    Stata 
//  task:       Sample and diagnostics 
//  project:    Markets  

version
clear all
macro drop _all
set linesize 80
set more off
local tag " 07-05-23| Cleaned 06-06-24"
local file "MAR02-SampDiag"
local note "|`tag' | `file'"
local opt "noparen sideway excel noaster  bdec(2)  sdec(2)  pdec(3)   adec(2) e(r2) stats(coef se pval)"
local iv "fraser"
local cont "infantmort  edu unemp  popdense perurban  sexratio"
local cont2 "infantmort  gini edu unemp  popdense perurban  sexratio"

//	#0
//	loading data 
use MAR01-DataClean, clear 

//	#1
//	getting sample 
xtset CID year 
xtreg rhom `iv' `cont', fe 
tab nation if e(sample)==1
gen sample=1 if e(sample)==1 
/* Nations to drop 
Azerbaijan
Belarus
Bosnia and Herzegovina
Cabo Verde
Iran (Islamic Republic of)
Iraq
Lebanon
Mongolia
Seychelles
Suriname
Tajikistan
United Arab Emirates
*/ 
replace sample=. if nation=="Azerbaijan"
replace sample=. if nation=="Belarus"
replace sample=. if nation=="Bosnia and Herzegovina"
replace sample=. if nation=="Cabo Verde"
replace sample=. if nation=="Iran (Islamic Republic of)"
replace sample=. if nation=="Iraq"
replace sample=. if nation=="Lebanon"
replace sample=. if nation=="Mongolia"
replace sample=. if nation=="Seychelles"
replace sample=. if nation=="Suriname"
replace sample=. if nation=="Tajikistan"
replace sample=. if nation=="United Arab Emirates"

tab nation if rhom==0
replace sample=. if rhom==0

tab nation if sample==1
drop if sample!=1

//	#2
//	normal 
* qladder rhom 
gen lrhom=log(rhom) 
label var lrhom "Ln Homicide Victimization Rates" 
note lrhom: `note'. 

//	#3
//	station 
xtunitroot fisher rhom, dfuller lags(0) 

foreach var in `iv' `cont'  {
	xtunitroot fisher `var', dfuller lags(0) 
	}
	
//	#4
//  Autocorrelation 
xtserial rhom `iv' `cont'
xtserial lrhom `iv' `cont'
xtserial lrhom `iv' `cont2'
xtserial rhom `iv' `cont2'

//	#5
//	Cross-Sectional Dependence 
xtreg rhom `iv' `cont' , fe
* xtcsd, pesaran abs
xtreg lrhom `iv' `cont2' , fe
* xtcsd, pesaran abs

/* Neither had enough obs */ 

//	#6
//	Homoscedastic 
xtreg rhom `iv' `cont' , fe
xttest3 

xtreg lrhom `iv' `cont' , fe
xttest3 

//	#7
//	Final model 
xtreg rhom `iv' `cont', fe vce(robust) 
outreg2 using `file', replace `opt' 

//	#8
//	save and close 
note:  Completed sample and pre-model diagnostics | `note'. 
notes
save `file'.dta, replace 
log close 
//